import axios from 'axios';

const instance = axios.create({
  baseURL: 'http://localhost:8080/',
  timeout: 10000,
  headers: {
    'X-Custom-Header': 'foobar',
    'Content-Type': 'application/json'
  }
});

instance.interceptors.request.use(
  config => {
    // console.log(config);
    return config;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
);

instance.interceptors.response.use(
  response => {
    // console.log(response);
    return response;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
);

const AxiosMethods={
    get(endpoint, params) {
        return instance.get(endpoint, params);
    },
    post(endpoint, data) {
        return instance.post(endpoint, data);
    },
    put(endpoint, data) {
        return instance.put(endpoint, data);
    },
    delete(endpoint) {
        return instance.delete(endpoint);
    }
}
export default AxiosMethods;